package com.wkr.order.controller;

import com.wkr.common.CommonResponse;
import com.wkr.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/order/train")
@Slf4j
public class OrderController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private IOrderService trainOrderServiceImpl;

    @PostMapping("/create")
    public CommonResponse<Boolean> createOrder() {
        try {
            trainOrderServiceImpl.create();
        } catch (Exception e) {
            log.error("创建订单异常", e);
            return CommonResponse.fail("-1", e.getMessage());
        }
        return CommonResponse.success(Boolean.TRUE);
    }

    @PostMapping("/hi")
    public CommonResponse<String> hi() {
        return CommonResponse.success(port);
    }

    @PostMapping("/test")
    public CommonResponse<Boolean> testForTimeOut() throws InterruptedException {
        TimeUnit.SECONDS.sleep(3);
        return CommonResponse.success(Boolean.TRUE);
    }

}
